Jump to content

[SOLVED] Get Texture of Block in World


Bedrock_Miner

Recommended Posts

Hi Guys!

 

I want to create a landmine in minecraft, which has the size of a pressureplate and should take the texture of the block below to hide itself. But how I can do this? :-\

Is there any possibility? Such as:

worldobj.getBlockTexture(X,Y,Z,side);

Also I don't really know, how to create the Explosion if a player or mob (or only a player) step on the mine...

 

I'm not adding any code, because I really have no Idea.

 

Can you help me please?

Link to comment
Share on other sites

This is not an easy thing to do.

 

The Secret Rooms mod built an entire camo rendering system to do just this.  Unfortunately, I haven't been able to replicate it inside my own mods.

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.

Link to comment
Share on other sites

Try something like this

 

int blockID = par1World.getBlockID(blockX, blockY, blockZ);
Block b0 = Block.blockList[blockID];
b0.getIcon(side, metadata);

 

Won't work.  All instances of the block would share textures.  As soon as you placed a second one that was on top of a different block, the first one would change.

 

(Tip: block classes are not instanced for each block in the world, there is only a single instance of every block class)

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.

Link to comment
Share on other sites

Try something like this

 

int blockID = par1World.getBlockID(blockX, blockY, blockZ);
Block b0 = Block.blockList[blockID];
b0.getIcon(side, metadata);

 

Won't work.  All instances of the block would share textures.  As soon as you placed a second one that was on top of a different block, the first one would change.

 

(Tip: block classes are not instanced for each block in the world, there is only a single instance of every block class)

 

I forgot about that. Well... he could create a different block for each texture (the most common), or just use a transparent texture xD

Link to comment
Share on other sites

It's actually pretty simple.

Override getBlockTexture:

@Override
public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side) {
    int idBelow = world.getBlockId(x, y - 1, z);
    if (Block.blocksList[idBelow] != null) {
        return Block.blocksList[idBelow].getBlockTexture(world, x, y - 1, z, side);
    } else {
        return blockIcon; // fallback if no block below for some reason
    }
}

 

Read above.

E.g.: he places the first mine on top of dirt. The mine would have the dirt texture. He places the second mine on top of stone, both mines would change to stone.

Link to comment
Share on other sites

E.g.: he places the first mine on top of dirt. The mine would have the dirt texture. He places the second mine on top of stone, both mines would change to stone.

It would not. Read my code. I did exactly that in a very old mod of mine, it works just fine.

Link: http://www.minecraftforum.net/topic/1246526-132-betterpressureplates-pressure-plates-that-adapt-to-the-block-below-beta/

 

That's for 1.3.2, it may not work now. But someone try it and let us know

Link to comment
Share on other sites

E.g.: he places the first mine on top of dirt. The mine would have the dirt texture. He places the second mine on top of stone, both mines would change to stone.

It would not. Read my code. I did exactly that in a very old mod of mine, it works just fine.

Link: http://www.minecraftforum.net/topic/1246526-132-betterpressureplates-pressure-plates-that-adapt-to-the-block-below-beta/

 

That's for 1.3.2, it may not work now. But someone try it and let us know

 

It still works. Also it would either be entirely removed or wouldn't have an Icon as return value if it didn't work. ;)

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

It's actually pretty simple.

Override getBlockTexture:

@Override
public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side) {
    int idBelow = world.getBlockId(x, y - 1, z);
    if (Block.blocksList[idBelow] != null) {
        return Block.blocksList[idBelow].getBlockTexture(world, x, y - 1, z, side);
    } else {
        return blockIcon; // fallback if no block below for some reason
    }
}

 

I tried this code, it works fine. But if I place the mine on grass, it takes a stone texture...  :-\

How can I avoid this?

 

(And how can I spawn the explosion if somebody walkes on the mine?)

Link to comment
Share on other sites

It's actually pretty simple.

Override getBlockTexture:

@Override
public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side) {
    int idBelow = world.getBlockId(x, y - 1, z);
    if (Block.blocksList[idBelow] != null) {
        return Block.blocksList[idBelow].getBlockTexture(world, x, y - 1, z, side);
    } else {
        return blockIcon; // fallback if no block below for some reason
    }
}

 

I tried this code, it works fine. But if I place the mine on grass, it takes a stone texture...  :-\

How can I avoid this?

 

(And how can I spawn the explosion if somebody walkes on the mine?)

 

It's probably not the stone texture, but the un-colorized grass texture. You would need to get the color from the block below, too. There's a method called colorMultiplier. Don't worry about the first parameter, it's basically a world instance (but don't cast it!). Get the block instance below your block and return the same method with the instance (instance.getColorMultiplier), while giving the method the same parameters.

To trigger something on impact, look at the pressure plate code or at the Cactus code.

To create an explosion, look at the TNT entity or at the Creeper. Hint: it's one line of code.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

I didn't really understand how to use the ColorMultiplier.

Could you please give me a code example?  :-\

 

(I managed to create an explosion, but it doesn't deal damage. Why? You hear the sound and the particles are rendered, but you don't get any damage and don't fly away... :-\)

Link to comment
Share on other sites

I didn't really understand how to use the ColorMultiplier.

Could you pleas give me a code example?  :-\

 

Have some pseudocode:

Block block = Block.blocksList[iBlockAccess.getBlockID(x, y-1, z)];
if(block != null)
    return block.getColorMultiplier(iBlockAccess, x, y-1, z)
else
    return super.getColorMultiplier(...)

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

(I managed to create an explosion, but it doesn't deal damage. Why? You hear the sound and the particles are rendered, but you don't get any damage and don't fly away... :-\)

 

try this

 

worldObj.newExplosion((Entity)null, this.posX, this.posY, this.posZ, (float)this.explosionRadius, true, true);

Link to comment
Share on other sites

Sorry, but I just don't get it right. The method colorMultiplier has got an integer value as return type, but I need an Icon. How can I manage this?

public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side) {
    int idBelow = world.getBlockId(x, y - 1, z);
    if (Block.blocksList[idBelow] != null) {
        return Block.blocksList[idBelow].getBlockTexture(world, x, y - 1, z, side);
    } else {
        return blockIcon;// fallback if no block below for some reason
    }
}

(I've used the old code, because your returns a normal dirt texture on a grass Block)

 

@ColdFox: The explosions work now :)

Link to comment
Share on other sites

Sorry, but I just don't get it right. The method colorMultiplier has got an integer value as return type, but I need an Icon. How can I manage this?

public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side) {
    int idBelow = world.getBlockId(x, y - 1, z);
    if (Block.blocksList[idBelow] != null) {
        return Block.blocksList[idBelow].getBlockTexture(world, x, y - 1, z, side);
    } else {
        return blockIcon;// fallback if no block below for some reason
    }
}

(I've used the old code, because your returns a normal dirt texture on a grass Block)

 

@ColdFox: The explosions work now :)

 

No, that code doesn't go to the texture method! Use the previous code you did there. The code I've provided goes into the getColorMultiplier method, which you should override in your block class.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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.