Jump to content

MetaData Block Tile Entity?


memanlolz

Recommended Posts

Well, i have this block, which i want to have 33 subblocks, and everywhere i look, everyone just says "You need TE". i realise i need a TE... just how the heck do i make one!?

Code : MetaDataBlock

private static final TileEntityMegaBlock TileEntityMega = new TileEntityMegaBlock();
private static final TileEntityMegaBlock TE = TileEntityMega;
public static Icon[] IconArray;
    public static String[] IconNames = {"stone","stonebrick","dirt","wood","bedrock","sand","gravel","oreCoal","oreIron","oreGold","oreLapis","oreDiamond","oreRedstone","blockIron","blockGold","blockDiamond","blockLapis","blockRedstone","cloth_0","cloth_1","cloth_2","cloth_3","cloth_4","cloth_5","cloth_6","cloth_7","cloth_8","cloth_9","cloth_10","cloth_11","cloth_12","cloth_13","cloth_14","cloth_15"};

public BlockMegaBlock(int par1) {
	super(par1, Material.ground);
	this.setBlockBounds(0.30F, 0.30F, 0.30F, 0.70F, 0.70F, 0.70F);
}
public boolean hasTileEntity(int meta){
	return true;
}
public TileEntity createNewTileEntity(World world, int meta) {
	return TE;
}
@Override
public void onBlockAdded(World par1World, int par2, int par3, int par4){
	par1World.setBlockTileEntity(par2, par3, par4, TileEntityMega);
	this.TE.worldObj.setBlockTileEntity(par2, par3, par4, TileEntityMega);
	super.onBlockAdded(par1World, par2, par3, par4);
	par1World.setBlockTileEntity(par2, par3, par4, TileEntityMega);
	this.TE.worldObj.setBlockTileEntity(par2, par3, par4, TileEntityMega);
}
public boolean isOpaqueCube()
{
	 return false;
}
public void registerIcons(IconRegister par1IconRegister)
    {
	this.IconArray = new Icon[iconNames.length];
	for(int i=0;i<IconNames.length;i++){
		System.out.println("Registered MegaBlock #"+i+" With Image "+this.IconNames[i]);
		this.IconArray[i] = par1IconRegister.registerIcon(this.IconNames[i]); 
	}
    }
public Icon getIcon(int par1, int par2)
    {
	return this.IconArray[par2];		
    }
public int idDropped(int par1, Random par2Random, int par3)
    {
	return this.blockID;
    }
public int quantityDropped(Random par1Random)
    {
        return 1;
    } 
public int damageDropped(int i){ //Tells it what block it drops and also for creative mode pick block
	return i;
}
@SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) //Adds the metadata blocks to the creative inventory
{
	for(int i=0;i<IconNames.length;i++){
		par3List.add(new ItemStack(par1, 1, i));
	}
}

 

 

Tile Entity

package com.yofungate.mods.YellowMech.misc;

import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;

public class TileEntityMegaBlock extends TileEntity {
public static int blockMetadata = 0;
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
blockMetadata = nbt.getInteger("BMD") & 0xFF;
System.out.print(blockMetadata);
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
System.out.print(blockMetadata);
nbt.setInteger("BMD", this.blockMetadata);
}
public static int GetMeta(){
	return blockMetadata;
}
}

 

Link to comment
Share on other sites

Thats good! Now you only need an itemBlock which has this function in it to return the metadata

 

public static ItemBlockMulitBlock extends ItemBlock

{

  public ItemBlockMultiBlock(int par1)

  {

      super(par1);

      setHasSubtypes(true)

  }

 

  @Override

  public int getBlockMetadata(int par1)

  {

        return par1;

    }

 

}

 

than you also need an extra item which changes the tileentity when your placing the block. Than you can have. The Rest you have to find out yourself^^

Link to comment
Share on other sites

i already have an itemblock.

 

package com.yofungate.mods.YellowMech.misc;

import com.yofungate.mods.YellowMech.common.YellowMech;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;

public class ItemBlockMegaBlock extends ItemBlock {

public ItemBlockMegaBlock(int par1) {
	super(par1);
	this.setMaxDamage(0);
	this.setHasSubtypes(true);
}
@SideOnly(Side.CLIENT)

public Icon getIconFromDamage(int par1) //Gets the texture
{
         return YellowMech.MegaBlock.getIcon(2, par1);
}
public int getMetadata(int par1) //Returns the metadata value
{
         return par1;
}
public String getItemNameIS(ItemStack is) //Get's the item incode name from an itemstack
{
         
         return "YellowMech." + BlockMegaBlock.IconNames[is.getItemDamage()];
}
}

 

Link to comment
Share on other sites

i got my ItemBlock with

package com.yofungate.mods.YellowMech.misc;

import com.yofungate.mods.YellowMech.common.YellowMech;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;

public class ItemBlockMegaBlock extends ItemBlock {

private static final TileEntity TileEntityMegaBlock = new TileEntityMegaBlock();
public ItemBlockMegaBlock(int par1) {

	super(par1);
	this.setMaxDamage(0);
	this.setHasSubtypes(true);
}
@SideOnly(Side.CLIENT)

public Icon getIconFromDamage(int par1) //Gets the texture
{
         return YellowMech.MegaBlock.getIcon(2, par1);
}
public int getMetadata(int par1) //Returns the metadata value
{
         return par1;
}
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10){

        if (par7 == 0)
        {
            --par5;
        }

        if (par7 == 1)
        {
            ++par5;
        }

        if (par7 == 2)
        {
            --par6;
        }

        if (par7 == 3)
        {
            ++par6;
        }

        if (par7 == 4)
        {
            --par4;
        }
        if (par7 == 5){
        	++par4;
        }
        int x=par4, y=par5, z=par6;

	par3World.setBlock(x, y, z, this.getBlockID());
	par3World.setBlockTileEntity(x, y, z, TileEntityMegaBlock);
	par3World.setBlockMetadataWithNotify(x, y, z, par1ItemStack.getItemDamage(), 3);
	return true;
}
public String getItemNameIS(ItemStack is) //Get's the item incode name from an itemstack
{
         
         return "YellowMech." + BlockMegaBlock.IconNames[is.getItemDamage()];
}
}

Link to comment
Share on other sites

There is a ModLoader Mod which can help you alot. It also implemented Forge.

PowerCraft.

 

Or Read how the skulls are get Placed^^ i do not have the time (and i do not waste my time with coding for other for free). Find it out yourself.

 

I can tell you what you need.

 

You need:

 

Block & ItemBlock (which have the submeta inside(submeta can big as you want))

Thats the block now for the placeing.

 

You simply need an item which is placeing your Block. and changes the tileentity.

That the way ic2 make it with his cables. Its only 1 cable tile and the items changes only the value.

 

If you ask more than i just everytime read it from vannila there is all you need!

Link to comment
Share on other sites

Moritz is mostly right. You'll need to somehow modify the TE with one or more items. Or CreativeTabs.

 

In every case, be it different algorithms on block updates, textures, or rendering, you'll first need to get the TE and do all the tests you need in order to distinguish the subtype. Example:

 

 

public Icon getBlockTexture( IBlockAccess blockAccess, int x, int y, int y, int side ) {
    MyTileEntity te = (MyTileEntity)blockAccess.getBlockTileEntity(x, y, z);
    
    switch( te.type ) {
        case 0: default:
            return Block.wood.getIcon(side, 0);
        case 1:
            return Block.grass.getIcon(side, 0);
    }
}

 

 

In this example, you'd only have 2 different types for simplicity. Depending on the state of your TE, you'd do different things respectively. Fair enough, huh? It all comes down to... well, that.

Hope that's enough to get you started. If not... explain your problem better.

Link to comment
Share on other sites

  • 1 month later...

Okay, i somehow did everything untill now, now i need to know, how do i make it Save the tile entity?

 

Codes So Far,

Tile Entity

package com.yofungate.mods.YellowMech.misc;

import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;

public class TileEntityMegaBlock extends TileEntity {
public static int blockMetadata = -1;

public TileEntityMegaBlock(){
}
@Override
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
this.blockMetadata = nbt.getInteger("BMD");
}
@Override
public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt);
nbt.setInteger("BMD", this.blockMetadata);
}
public int GetMeta(){
	return this.blockMetadata;
}
public void setMeta(int i) {
	this.blockMetadata = i;
}
public TileEntity returnTE(){
	return this;
}
    public Packet getDescriptionPacket()
    {
        NBTTagCompound nbttagcompound = new NBTTagCompound();
        this.writeToNBT(nbttagcompound);
        return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 4, nbttagcompound);
    }
}

 

 

ItemBlock

package com.yofungate.mods.YellowMech.misc;

import com.yofungate.mods.YellowMech.common.YellowMech;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World;

public class ItemBlockMegaBlock extends ItemBlock {
    public static String[] IconNames = {"stone","stonebrick","dirt","wood","bedrock","sand","gravel","oreCoal","oreIron","oreGold","oreLapis","oreDiamond","oreRedstone","blockIron","blockGold","blockDiamond","blockLapis","blockRedstone","cloth_0","cloth_1","cloth_2","cloth_3","cloth_4","cloth_5","cloth_6","cloth_7","cloth_8","cloth_9","cloth_10","cloth_11","cloth_12","cloth_13","cloth_14","cloth_15"};
private static final TileEntity TE = new TileEntityMegaBlock();
public ItemBlockMegaBlock(int par1) {

	super(par1);
	this.setMaxDamage(33);
	this.setHasSubtypes(true);
}
@SideOnly(Side.CLIENT)

public Icon getIconFromDamage(int par1) //Gets the texture
{		 
	     this.TE.blockMetadata=par1;
         return YellowMech.MegaBlock.getIcon(2, this.TE.blockMetadata);
}
public int getMetadata(int par1) //Returns the metadata value
{
         return this.TE.blockMetadata;
}
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10){

        if (par7 == 0)
        {
            --par5;
        }

        if (par7 == 1)
        {
            ++par5;
        }

        if (par7 == 2)
        {
            --par6;
        }

        if (par7 == 3)
        {
            ++par6;
        }

        if (par7 == 4)
        {
            --par4;
        }
        if (par7 == 5){
        	++par4;
        }
        int x=par4, y=par5, z=par6;
        this.TE.blockMetadata = par1ItemStack.getItemDamage();
	par3World.setBlock(x, y, z, this.getBlockID());
	par3World.setBlockTileEntity(x, y, z, this.TE);
	par3World.getBlockTileEntity(x, y, z).blockMetadata=this.TE.blockMetadata;
	par3World.getBlockTileEntity(x,y,z).blockMetadata=this.TE.blockMetadata;
	System.out.println("Placed? meta = "+this.TE.blockMetadata+"Block Meta = "+par3World.getBlockTileEntity(x,y,z).blockMetadata);
        if (par1ItemStack.stackSize == 0)
        {
            return false;
        }
        else if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack))
        {
            return false;
        }
	return true;
}
    public int damageDropped(int par1)
    {
        return this.TE.blockMetadata;
    }
public String getItemNameIS(ItemStack is) //Get's the item incode name from an itemstack
{
			this.TE.blockMetadata=is.getItemDamage();
         return "YellowMech." + this.IconNames[is.getItemDamage()];
}
}

 

Block.

 

package com.yofungate.mods.YellowMech.misc;

import java.util.List;
import java.util.Random;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
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.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockMegaBlock extends BlockContainer{
private static TileEntity TE  = new TileEntityMegaBlock();
public static Icon[] IconArray;
public BlockMegaBlock(int par1) {
	super(par1, Material.ground);
	this.setBlockBounds(0.30F, 0.30F, 0.30F, 0.70F, 0.70F, 0.70F);

}
public boolean hasTileEntity(int meta){
	return true;
}
public TileEntity createNewTileEntity(World world) {
	this.TE.blockMetadata = 9;
    	System.out.println("Block Method Recieved. Meta = "+this.TE.blockMetadata);
	return new TileEntityMegaBlock();
}
public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
{
	this.setBlockBounds(0.30F, 0.30F, 0.30F, 0.70F, 0.70F, 0.70F);
	float miX,miY,miZ,maX,maY,maZ;
	miX = (float)this.getBlockBoundsMinX();miY = (float)this.getBlockBoundsMinY();miZ = (float)this.getBlockBoundsMinZ();maX = (float)this.getBlockBoundsMaxX();maY = (float)this.getBlockBoundsMaxY();maZ = (float)this.getBlockBoundsMaxZ();
		if(!par1IBlockAccess.isAirBlock(par2-1, par3, par4)){
			this.setBlockBounds(0, miY, miZ, maX, maY, maZ);
		}
	miX = (float)this.getBlockBoundsMinX();miY = (float)this.getBlockBoundsMinY();miZ = (float)this.getBlockBoundsMinZ();maX = (float)this.getBlockBoundsMaxX();maY = (float)this.getBlockBoundsMaxY();maZ = (float)this.getBlockBoundsMaxZ();
		if(!par1IBlockAccess.isAirBlock(par2+1, par3, par4)){
			this.setBlockBounds(miX, miY, miZ, 1, maY, maZ);
		}
	miX = (float)this.getBlockBoundsMinX();miY = (float)this.getBlockBoundsMinY();miZ = (float)this.getBlockBoundsMinZ();maX = (float)this.getBlockBoundsMaxX();maY = (float)this.getBlockBoundsMaxY();maZ = (float)this.getBlockBoundsMaxZ();
		if(!par1IBlockAccess.isAirBlock(par2, par3-1, par4)){
			this.setBlockBounds(miX, 0, miZ, maX, maY, maZ);
		}
	miX = (float)this.getBlockBoundsMinX();miY = (float)this.getBlockBoundsMinY();miZ = (float)this.getBlockBoundsMinZ();maX = (float)this.getBlockBoundsMaxX();maY = (float)this.getBlockBoundsMaxY();maZ = (float)this.getBlockBoundsMaxZ();
		if(!par1IBlockAccess.isAirBlock(par2, par3+1, par4)){
			this.setBlockBounds(miX, miY, miZ, maX, 1, maZ);
		}
	miX = (float)this.getBlockBoundsMinX();miY = (float)this.getBlockBoundsMinY();miZ = (float)this.getBlockBoundsMinZ();maX = (float)this.getBlockBoundsMaxX();maY = (float)this.getBlockBoundsMaxY();maZ = (float)this.getBlockBoundsMaxZ();
		if(!par1IBlockAccess.isAirBlock(par2, par3, par4-1)){
			this.setBlockBounds(miX, miY, 0, maX, maY, maZ);
		}
	miX = (float)this.getBlockBoundsMinX();miY = (float)this.getBlockBoundsMinY();miZ = (float)this.getBlockBoundsMinZ();maX = (float)this.getBlockBoundsMaxX();maY = (float)this.getBlockBoundsMaxY();maZ = (float)this.getBlockBoundsMaxZ();
		if(!par1IBlockAccess.isAirBlock(par2, par3, par4+1)){
			this.setBlockBounds(miX, miY, miZ, maX, maY, 1);
		}
    }
    public void func_82541_d(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    {
	this.setBlockBounds(0.30F, 0.30F, 0.30F, 0.70F, 0.70F, 0.70F);
	float miX,miY,miZ,maX,maY,maZ;
	miX = (float)this.getBlockBoundsMinX();miY = (float)this.getBlockBoundsMinY();miZ = (float)this.getBlockBoundsMinZ();maX = (float)this.getBlockBoundsMaxX();maY = (float)this.getBlockBoundsMaxY();maZ = (float)this.getBlockBoundsMaxZ();
		if(!par1IBlockAccess.isAirBlock(par2-1, par3, par4)){
			this.setBlockBounds(0, miY, miZ, maX, maY, maZ);
		}
	miX = (float)this.getBlockBoundsMinX();miY = (float)this.getBlockBoundsMinY();miZ = (float)this.getBlockBoundsMinZ();maX = (float)this.getBlockBoundsMaxX();maY = (float)this.getBlockBoundsMaxY();maZ = (float)this.getBlockBoundsMaxZ();
		if(!par1IBlockAccess.isAirBlock(par2+1, par3, par4)){
			this.setBlockBounds(miX, miY, miZ, 1, maY, maZ);
		}
	miX = (float)this.getBlockBoundsMinX();miY = (float)this.getBlockBoundsMinY();miZ = (float)this.getBlockBoundsMinZ();maX = (float)this.getBlockBoundsMaxX();maY = (float)this.getBlockBoundsMaxY();maZ = (float)this.getBlockBoundsMaxZ();
		if(!par1IBlockAccess.isAirBlock(par2, par3-1, par4)){
			this.setBlockBounds(miX, 0, miZ, maX, maY, maZ);
		}
	miX = (float)this.getBlockBoundsMinX();miY = (float)this.getBlockBoundsMinY();miZ = (float)this.getBlockBoundsMinZ();maX = (float)this.getBlockBoundsMaxX();maY = (float)this.getBlockBoundsMaxY();maZ = (float)this.getBlockBoundsMaxZ();
		if(!par1IBlockAccess.isAirBlock(par2, par3+1, par4)){
			this.setBlockBounds(miX, miY, miZ, maX, 1, maZ);
		}
	miX = (float)this.getBlockBoundsMinX();miY = (float)this.getBlockBoundsMinY();miZ = (float)this.getBlockBoundsMinZ();maX = (float)this.getBlockBoundsMaxX();maY = (float)this.getBlockBoundsMaxY();maZ = (float)this.getBlockBoundsMaxZ();
		if(!par1IBlockAccess.isAirBlock(par2, par3, par4-1)){
			this.setBlockBounds(miX, miY, 0, maX, maY, maZ);
		}
	miX = (float)this.getBlockBoundsMinX();miY = (float)this.getBlockBoundsMinY();miZ = (float)this.getBlockBoundsMinZ();maX = (float)this.getBlockBoundsMaxX();maY = (float)this.getBlockBoundsMaxY();maZ = (float)this.getBlockBoundsMaxZ();
		if(!par1IBlockAccess.isAirBlock(par2, par3, par4+1)){
			this.setBlockBounds(miX, miY, miZ, maX, maY, 1);
		}
    }
    public void setBlockBoundsForItemRender()
    {
        	this.setBlockBounds(0.30F, 0.30F, 0.30F, 0.70F, 0.70F, 0.70F);
    }
public boolean isOpaqueCube()
{
	 return false;
}
public void registerIcons(IconRegister par1IconRegister)
    {
	this.IconArray = new Icon[itemBlockMegaBlock.IconNames.length];
	for(int i=0;i<ItemBlockMegaBlock.IconNames.length;i++){
		this.IconArray[i] = par1IconRegister.registerIcon(ItemBlockMegaBlock.IconNames[i]); 
	}
    }
 public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
    {
	 try{
        return this.getIcon(par5, par1IBlockAccess.getBlockTileEntity(par2,par3,par4).blockMetadata);
	 }catch(Exception e){
		return this.getIcon(par5, 0);
	 }
	}
public Icon getIcon(int par1, int par2)
{
	return this.IconArray[par2];
    }
public int idDropped(int par1, Random par2Random, int par3)
    {
	return this.blockID;
    }
public int quantityDropped(Random par1Random)
    {
        return 1;
    } 
public int damageDropped(int i){ //Tells it what block it drops and also for creative mode pick block
	return this.TE.blockMetadata;
}
@SideOnly(Side.CLIENT)
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) //Adds the metadata blocks to the creative inventory
{
	for(int i=0;i<ItemBlockMegaBlock.IconNames.length;i++){
		par3List.add(new ItemStack(par1, 1, i));
	}
}
}

 

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.