Jump to content

Changing texture of block while ingame?


Atijaf

Recommended Posts

Would it be possible to create a block the mimics the texture of any block I want?

 

This one block would be able to take on any textures... So it could look like grass, stone, sand(without the attributes of falling).

Is that possible?

 

I wanted to make a minecraft world with structures that are unbreakable.

 

I am hoping to be able to use a command to change the texture of this block.

Link to comment
Share on other sites

Hi, I'm pretty sure you can use ISmartBlockModel for this to return different IBakedModels based on NBT. I'm assuming this is correct considering you can do this with items. For example, one block model has the stone texture and another has the grass. When you send your command, have the player hold the block you want to change and convert that into an itemstack. Then, save NBT to it saying to render whatever block you typed in your command - test if the NBT boolean is true, and if it is return the new model in handleBlockState(), I believe it's called (may be named differently). This way, the new models you returned will contain the different textures. Heck, for your ModelResourceLocations just use the vanilla .JSON block models. This is completely untested, I've only used ISmartItemModel and I am yet to use ISmartBlockModel (some names may be incorrect), but in theory this should work as it does in items.

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

Link to comment
Share on other sites

There are 2 components to this question: one is the block as seen when placed, and the other is the block as seen when in your inventory / held.

 

The first is the simplest: you make your block as normal, give it a TileEntity that can store a Block and meta value pair, then in your ISimpleBlockModel you fetch the extended state of your block to get the IBlockState to render. It would look something like this:

@Override
public IBakedModel handleBlockState(IBlockState state) {
if (state instanceof IExtendedBlockState) {
	IBlockState renderState = ((IExtendedBlockState) state).getValue(BlockDungeonStone.RENDER_BLOCK);
	if (renderState != null) {
		IBakedModel renderModel = mc.getBlockRendererDispatcher().getBlockModelShapes().getModelForState(renderState);
		if (renderModel instanceof ISmartBlockModel) {
			renderModel = ((ISmartBlockModel) renderModel).handleBlockState(renderState);
		}
		return renderModel;
	}
}
return defaultModel;
}

 

For the block as an item, you need an ISmartItemModel along with your custom ItemBlock - the ItemBlock should be able to store whatever BlockState is necessary to recreate the Block + TileEntity you place in the world, and should also have a way to switch textures such as sneak+right-clicking on a block with it in your hand, depending of course on how you want your block to work.

 

To register your block with a custom model, you need to use the ModelBakeEvent. TheGreyGhost's MinecraftByExample project has some examples that should prove helpful.

Link to comment
Share on other sites

Alright.  I've got it working.  There may be a fatal flaw as to what I want.

 

When I place this block, it looks like stone. (What I want it to look like for current purpose)

 

I now change it to look like a snow block.

 

When I place this block, it looks like a snow block... But it also updates the block that I placed before into looking like a snow block.

 

I'm wanting the two blocks that I placed down to look like they did originally.  Is that possible?

Link to comment
Share on other sites

Funny enough.  I haven't messed with Tile Entities as much as I wish I had.

I looked up a tutorial and I have a TileEntity class for my block now.

 

What kind of class fields would I put into my TileEntity class?  And would I use nbt data?

 

My Mimic Block class

http://pastebin.com/uGUKsVYM

 

My Tile Entity Mimic Block class

http://pastebin.com/QvZi553P

 

Thanks for the prompt replies.

Link to comment
Share on other sites

And would I use nbt data?

 

In order to send the data from server to client (getDescriptionPacket) and to save the data to the hard drive and load it back again.

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

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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