Jump to content

Recommended Posts

Posted

I would make a Block which faces with a specific Texture to the Player. All siedes have one texture and here is the code of the class:

 

 

package mods.minemeister01.MCM.blocks;

import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLiving;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class MultiBlock extends CreateMultiTexturedBlock{

public MultiBlock(int id, Material material, String text_top, String text_bottom, String text_side_1, String text_side_2, String text_side_3, String text_side_4) {
	super(id, material);
	this.texture_top = text_top;
	this.texture_bottom = text_bottom;
	this.texture_side_1 = text_side_1;
	this.texture_side_2 = text_side_2;
	this.texture_side_3 = text_side_3;
	this.texture_side_4 = text_side_4;
}

@SideOnly(Side.CLIENT)
public Icon getIcon(int i, int j){
	if (i == 0) {
		return bottom;
	}

	if (i == 1) {
		return top;
	}

	if (i == 2) {
		return side_1;
	}

	if (i == 3) {
		return side_2;
	}

	if (i == 4) {
		return side_3;
	}

	else {
		return side_4;
	}
}

@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister){
	this.side_1 = par1IconRegister.registerIcon(text + texture_side_1);
	this.side_2 = par1IconRegister.registerIcon(text + texture_side_2);
	this.side_3 = par1IconRegister.registerIcon(text + texture_side_3);
	this.side_4 = par1IconRegister.registerIcon(text + texture_side_4);
	this.top = par1IconRegister.registerIcon(text + texture_top);
	this.bottom = par1IconRegister.registerIcon(text + texture_bottom);
}
}

 

 

And the code of the CreateMultiTexturedBlock class:

 

 

package mods.minemeister01.MCM.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public abstract class CreateMultiTexturedBlock extends Block{

protected Icon side_1, side_2, side_3, side_4, bottom, top, sides;
protected String texture_top, texture_bottom, texture_side_1, texture_side_2, texture_side_3, texture_side_4, texture_sides;
protected String text = "minemeister01/MCM:";

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

@SideOnly(Side.CLIENT)
public abstract Icon getIcon(int i, int j);

@SideOnly(Side.CLIENT)
public abstract void registerIcons(IconRegister par1IconRegister);

}

 

 

I want that "side_1" faces to the player. I hope that anyone can help me.

Posted

Look at blocks like the furnace that get the player's facing when placed.

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

Search for sub blocks, thats the real name for what you call multiblock.

Multiblock is nowdays mostly used about structures which has several blocks but act as one :)

 

There are methods to get icons based of side and the metadata, using those and a Icon array should lead towards it working

If you guys dont get it.. then well ya.. try harder...

Posted

Search for sub blocks, thats the real name for what you call multiblock.

Multiblock is nowdays mostly used about structures which has several blocks but act as one :)

 

(And pumpkins are neither)

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

Search for sub blocks, thats the real name for what you call multiblock.

Multiblock is nowdays mostly used about structures which has several blocks but act as one :)

 

There are methods to get icons based of side and the metadata, using those and a Icon array should lead towards it working

 

Sorry, I don't meaned sub blocks but thanks. I meaned a multitextured block. I'll change the Discripion

Posted

oh well then it's exactly like the furnace mentioned by Draco!

And like I said above about Icon arrays and the getIcon methods.

 

You already have the solution :P

If you guys dont get it.. then well ya.. try harder...

Posted

If you want the texture to change as you move around the block so one side is always facing you, I'm not sure. Maybe set it to update the block on tick depending on the player's location?

If you want it like the furnace/pumpkin where it faces you when you place it, keep reading.

 

For the pumpkin feature, I mimicked it on my own a little more clearly than the pumpkin's code.

 

        @SideOnly(Side.CLIENT)
        @Override
        public void registerIcons(IconRegister iconRegister)
        {
                 this.blockIcon = iconRegister.registerIcon("stonebrick");
                 this.faceIcon = iconRegister.registerIcon("Obsidian:" + this.getUnlocalizedName().substring(5));
        }
        
        @SideOnly(Side.CLIENT)
        @Override
        public Icon getIcon(int side, int meta)
        {
        	if (meta == 0 && side == 3)
        		return faceIcon;
        	if (meta == 2 && side == 2)
        		return faceIcon;
        	if (meta == 1 && side == 4)
        		return faceIcon;
        	if (meta == 3 && side == 5)
        		return faceIcon;
        	return blockIcon;
        }

 

Most important is the getIcon method. The second parameter is the meta data for the block, specifically which direction the player is facing when they place it. This code sets the block facing you when you place it. You can go through and just have single if statements setting one side depending on side or meta so you can figure out the orientation of your block relative to the world and the values of side and meta. Hope this helps!

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

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.