Jump to content

Recommended Posts

Posted

Hello,

 

I'm first starting to mod in 1.8.9 and am interested in making a block that would change based on the block you use to right click on it.

 

I have a model working, and I used a texture I made for another block to test with, but I am wondering how I can take the texture of any block used on the block and display it?

 

In my json file for the model, I have a "cube" element which is what I want to change texture.

 

I believe I need to mess with the BlockState file, but looking at other blocks that change texture such as the brewing station, they created a bunch of different model files depending on the way it looks.

 

I don't see it being reasonable for me to make a different model file for every possible block that could be used on it.

 

Is there any way to dynamically change a texture on the model?  It uses 3 textures, I just need to change one of them.

 

5pZT11M.png

Posted

You are going to need a TileEntity to store the block the player r-clicked with, for one.

 

For two, you're going to need to make the renderer for this block look up, then render, the mesh for the stored block.

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

As for rendering the item itself, I use this method:

 

GlStateManager.pushMatrix();
GlStateManager.translate((float)x + 0.5F, (float)y + 0.5F, (float)z + 0.5F);
Minecraft.getMinecraft().getRenderItem().renderItem(ITEM, TransformType.GROUND);
GlStateManager.popMatrix();

 

Not quite sure if this is the best method for doing this, but it does work perfectly fine. Of course you will need to replace ITEM with an ItemStack.

Posted

So, if this was 1.7.10 I would understand that this goes in a render class.

 

I was following along some 1.8.9 tutorials since it seems a lot has changed for blocks and I'm not sure how to implement a rendering class since it seems to be handled by the blockstate.json and model json class.

 

I know the  renderer is being registered in this line:

 

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Modcraft.MODID + ":" + item.getUnlocalizedName().substring(5), "inventory"));

Posted

There is no need to make a TileEntity. You just have to create a special model that combines your model with the contained model.

 

Oh, I thought he wanted a block which contains an item.

 

I guess that you probably would not need a TileEntitySpecialRenderer in either case. But it is easier than trying to do it with models.

Posted

I meant TESR, not TileEntity.

You do need a TileEntity, just not a TESR.

 

So, I am new to using TileEntities and TESR, but I looked for an example.

 

This is the result.

 

OStoioq.png

 

It seems to have overridden my default model rendering with the rendering of the tile entitiy...Is there any way to have the TESR render inside the block rather than instead of the block?

Posted

Post your Block code

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

package net.modcraft.block;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.modcraft.Modcraft;
import net.modcraft.init.ModcraftBlocks;
import net.modcraft.tileentity.ShowCaseTileEntity;

public class ShowCaseBlock extends BlockContainer {

private Block block;

public ShowCaseBlock(Material materialIn, String name) {
	super(materialIn);
	block = Blocks.air;
	setUnlocalizedName(name); //Required.  Don't edit

	this.setStepSound(Block.soundTypeMetal); //Sets the sound played when stepped on

	this.setCreativeTab(Modcraft.tabModcraft); //Sets the creative tab

	this.setHarvestLevel("pickaxe", 0); //Sets the tool and harvest level

	this.setHardness(1.5F); //Hardness of block.  Currently equivalent to stone

	this.setResistance(10.0F); //Resistance to explosions.  Currently equivalent to stone

	this.setLightLevel(0.0F); //How much light to give off.  0.0F is none, 1.0F is max.  Torch is 0.9375F

	//this.setBlockUnbreakable(); //Uncomment this line to make it unbreakable

	GameRegistry.registerBlock(this, name); //Required.  Don't edit

	ModcraftBlocks.blocks.add(this); //Required.  Don't edit
}

@Override
public boolean isOpaqueCube() {
	return false;
}

@Override
public EnumWorldBlockLayer getBlockLayer() {
	return EnumWorldBlockLayer.CUTOUT;
}

public Block getBlock() {
	return block;
}

public void setBlock(Block block) {
	this.block = block;
}

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) {
	Block blockClickedWith = Block.getBlockFromItem(playerIn.getCurrentEquippedItem().getItem());
	if (blockClickedWith != null) {
		if (!worldIn.isRemote) {
			ShowCaseTileEntity te = (ShowCaseTileEntity) worldIn.getTileEntity(pos);
			te.setInventorySlotContents(0, playerIn.getCurrentEquippedItem());
		}
		/*this.block = blockClickedWith;
		IChatComponent message = new ChatComponentText("You clicked with block: " + this.block.getLocalizedName());
		playerIn.addChatMessage(message);*/
	}
	return true;
}

@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
	return new ShowCaseTileEntity();
}

@Override
public void breakBlock(World world, BlockPos pos, IBlockState blockstate) {
    ShowCaseTileEntity te = (ShowCaseTileEntity) world.getTileEntity(pos);
    InventoryHelper.dropInventoryItems(world, pos, te);
    super.breakBlock(world, pos, blockstate);
}


@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    if (stack.hasDisplayName()) {
        ((ShowCaseTileEntity) worldIn.getTileEntity(pos)).setCustomName(stack.getDisplayName());
    }
}
}

 

I register the renderer with this:

 

public static void registerRender(Block block) {
	Item item = Item.getItemFromBlock(block);
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Modcraft.MODID + ":" + item.getUnlocalizedName().substring(5), "inventory"));

}

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.