public class OmniRailBlock extends BlockRailBase {
public OmniRailBlock() {
super(false);
}
//This will tell minecraft not to render any side of our cube.
/*public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l)
{
return false;
}*/
@Override
public int onBlockPlaced(World p_149660_1_, int x, int y, int z, int side, float p_149660_6_, float p_149660_7_, float p_149660_8_, int p_149660_9_)
{
public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int x, int y, int z)
{
int side=0;
OmniTileEntity tile = (OmniTileEntity) p_149719_1_.getTileEntity(x, y, z);
if (tile != null)
{
side = tile.face;
}
int meta = p_149719_1_.getBlockMetadata(x, y, z);
//System.out.println("Meta is:" + side);
if(side == 0) {
//if(block is placed on face x,z (ground) facing up
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
//System.out.println("UP");
} else if(side == 1) {
//if block is placed on face x,z facing down
this.setBlockBounds(0.0F, 1.0F - 0.125F, 0.0F, 1.0F, 1.0F, 1.0F);
//System.out.println("DOWN");
}
else if(side == 2) {
//if block is placed on face x,y facing south
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.125F);
//System.out.println("SOUTH");
}
else if(side == 3) {
//if block is placed on face x,y facing north
this.setBlockBounds(0.0F, 0.0F, 1.0F-0.125F, 1.0F, 1.0F, 1.0F);
//System.out.println("NORTH");
}
else if(side == 4) {
//if block is placed on face y,z facing west
this.setBlockBounds(1.0F-0.125F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
//System.out.println("WEST");
}
else if(side == 5) {
//if block is placed on face y,z facing east
this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.125F, 1.0F, 1.0F);
//System.out.println("EAST");
}
}
//registering my tile entity for all Omni rails
@Override
public TileEntity createTileEntity(World world, int meta)
{
System.out.println("Tile Entity Registered");
return new OmniTileEntity();
}
@Override
public boolean hasTileEntity() {
return true;
}
//for reading values
/*
* OmniTileEntity tile = (OmniTileEntity) world.getBlockTileEntity(i, j, k);
if (tile != null)
{
int l = tile.customField;
}
*/
//overrides to allow for wall and ceiling placement (works )
public boolean canPlaceBlockAt(World p_149742_1_, int p_149742_2_, int p_149742_3_, int p_149742_4_)
{
return true;
/*return p_149742_1_.isSideSolid(p_149742_2_ - 1, p_149742_3_, p_149742_4_, EAST ) ||
p_149742_1_.isSideSolid(p_149742_2_ + 1, p_149742_3_, p_149742_4_, WEST ) ||
p_149742_1_.isSideSolid(p_149742_2_, p_149742_3_, p_149742_4_ - 1, SOUTH) ||
p_149742_1_.isSideSolid(p_149742_2_, p_149742_3_, p_149742_4_ + 1, NORTH) ||
p_149742_1_.isSideSolid(p_149742_2_, p_149742_3_ - 1, p_149742_4_, UP ) ||
p_149742_1_.isSideSolid(p_149742_2_, p_149742_3_ + 1, p_149742_4_, DOWN );
*/
}
public boolean canPlaceBlockOnSide(World p_149707_1_, int p_149707_2_, int p_149707_3_, int p_149707_4_, int p_149707_5_)
{
/*ForgeDirection dir = ForgeDirection.getOrientation(p_149707_5_);
if((dir == DOWN && p_149707_1_.isSideSolid(p_149707_2_, p_149707_3_ + 1, p_149707_4_, DOWN )) ||
(dir == UP && p_149707_1_.isSideSolid(p_149707_2_, p_149707_3_ - 1, p_149707_4_, UP )) ||
(dir == NORTH && p_149707_1_.isSideSolid(p_149707_2_, p_149707_3_, p_149707_4_ + 1, NORTH)) ||
(dir == SOUTH && p_149707_1_.isSideSolid(p_149707_2_, p_149707_3_, p_149707_4_ - 1, SOUTH)) ||
(dir == WEST && p_149707_1_.isSideSolid(p_149707_2_ + 1, p_149707_3_, p_149707_4_, WEST )) ||
(dir == EAST && p_149707_1_.isSideSolid(p_149707_2_ - 1, p_149707_3_, p_149707_4_, EAST ))) {
//currentSideOn = dir; //replaced with onBlockPlaced method
return true;
}
return false;*/
return true;
}
public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_)
{
//do nothing for now
}
// This Import list will grow longer with each additional tutorial.
// It's not pruned between full class postings, unlike other tutorial code.
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.block.material.Material;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
//import cpw.mods.fml.common.Mod.Init; //Used in 1.5.2 and before
import cpw.mods.fml.common.Mod.Instance;
//import cpw.mods.fml.common.Mod.PostInit; //Used in 1.5.2 and before
//import cpw.mods.fml.common.Mod.PreInit; //Used in 1.5.2 and before
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
//import cpw.mods.fml.common.network.NetworkMod; //Used in 1.6.4 and before
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry; //Used in 1.6.4 and before
@Mod(modid="generic", name="Generic", version="0.0.0")
//@NetworkMod(clientSideRequired=true, serverSideRequired=false) //Used in 1.6.4 and before
public class Generic
{
public static Block genericDirt;
public static Block omniRail;
@Instance(value="generic")
public static Generic instance;
@SidedProxy(clientSide="tutorial.generic.client.ClientProxy",
serverSide="tutorial.generic.CommonProxy")
public static CommonProxy proxy;
@EventHandler
public void preInit(FMLPreInitializationEvent event)//loader method
{
genericDirt = new GenericBlock(Material.ground)
.setHardness(0.5F).setStepSound(Block.soundTypeGravel)
.setBlockName("genericDirt").setCreativeTab(CreativeTabs.tabBlock);
omniRail = new OmniRailBlock()
.setHardness(0.7f).setStepSound(Block.soundTypeMetal)
.setBlockName("omniRail");
//omniRail.setBlockTextureName("Generic:OmniRail");//figure texture out later
GameRegistry.registerBlock(omniRail, "omniRail");
// End Basic Blocks
proxy.registerRenderers();
}
@EventHandler
public void init(FMLInitializationEvent event) {
}
Thank you so much, I changed my block class to implement ITileEntityProvider and changed the method in my block class from createTileEntity(world, int) to createNewTileEntity(world, int)
Block Class
package tutorial.generic;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRailBase;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class OmniRailBlock extends BlockRailBase {
public OmniRailBlock() {
super(false);
}
//This will tell minecraft not to render any side of our cube.
/*public boolean shouldSideBeRendered(IBlockAccess iblockaccess, int i, int j, int k, int l)
{
return false;
}*/
@Override
public int onBlockPlaced(World p_149660_1_, int x, int y, int z, int side, float p_149660_6_, float p_149660_7_, float p_149660_8_, int p_149660_9_)
{
OmniTileEntity tile = (OmniTileEntity) p_149660_1_.getTileEntity(x, y, z);
if (tile != null)
{
System.out.println("Side = "+side);
tile.face = side;
}
return p_149660_9_;
}
public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int x, int y, int z)
{
int side=0;
OmniTileEntity tile = (OmniTileEntity) p_149719_1_.getTileEntity(x, y, z);
if (tile != null)
{
side = tile.face;
}
int meta = p_149719_1_.getBlockMetadata(x, y, z);
//System.out.println("Meta is:" + side);
if(side == 0) {
//if(block is placed on face x,z (ground) facing up
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F);
//System.out.println("UP");
} else if(side == 1) {
//if block is placed on face x,z facing down
this.setBlockBounds(0.0F, 1.0F - 0.125F, 0.0F, 1.0F, 1.0F, 1.0F);
//System.out.println("DOWN");
}
else if(side == 2) {
//if block is placed on face x,y facing south
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.125F);
//System.out.println("SOUTH");
}
else if(side == 3) {
//if block is placed on face x,y facing north
this.setBlockBounds(0.0F, 0.0F, 1.0F-0.125F, 1.0F, 1.0F, 1.0F);
//System.out.println("NORTH");
}
else if(side == 4) {
//if block is placed on face y,z facing west
this.setBlockBounds(1.0F-0.125F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
//System.out.println("WEST");
}
else if(side == 5) {
//if block is placed on face y,z facing east
this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.125F, 1.0F, 1.0F);
//System.out.println("EAST");
}
}
//registering my tile entity for all Omni rails
@Override
public TileEntity createTileEntity(World world, int meta)
{
System.out.println("Tile Entity Registered");
return new OmniTileEntity();
}
@Override
public boolean hasTileEntity() {
return true;
}
//for reading values
/*
* OmniTileEntity tile = (OmniTileEntity) world.getBlockTileEntity(i, j, k);
if (tile != null)
{
int l = tile.customField;
}
*/
//overrides to allow for wall and ceiling placement (works )
public boolean canPlaceBlockAt(World p_149742_1_, int p_149742_2_, int p_149742_3_, int p_149742_4_)
{
return true;
/*return p_149742_1_.isSideSolid(p_149742_2_ - 1, p_149742_3_, p_149742_4_, EAST ) ||
p_149742_1_.isSideSolid(p_149742_2_ + 1, p_149742_3_, p_149742_4_, WEST ) ||
p_149742_1_.isSideSolid(p_149742_2_, p_149742_3_, p_149742_4_ - 1, SOUTH) ||
p_149742_1_.isSideSolid(p_149742_2_, p_149742_3_, p_149742_4_ + 1, NORTH) ||
p_149742_1_.isSideSolid(p_149742_2_, p_149742_3_ - 1, p_149742_4_, UP ) ||
p_149742_1_.isSideSolid(p_149742_2_, p_149742_3_ + 1, p_149742_4_, DOWN );
*/
}
public boolean canPlaceBlockOnSide(World p_149707_1_, int p_149707_2_, int p_149707_3_, int p_149707_4_, int p_149707_5_)
{
/*ForgeDirection dir = ForgeDirection.getOrientation(p_149707_5_);
if((dir == DOWN && p_149707_1_.isSideSolid(p_149707_2_, p_149707_3_ + 1, p_149707_4_, DOWN )) ||
(dir == UP && p_149707_1_.isSideSolid(p_149707_2_, p_149707_3_ - 1, p_149707_4_, UP )) ||
(dir == NORTH && p_149707_1_.isSideSolid(p_149707_2_, p_149707_3_, p_149707_4_ + 1, NORTH)) ||
(dir == SOUTH && p_149707_1_.isSideSolid(p_149707_2_, p_149707_3_, p_149707_4_ - 1, SOUTH)) ||
(dir == WEST && p_149707_1_.isSideSolid(p_149707_2_ + 1, p_149707_3_, p_149707_4_, WEST )) ||
(dir == EAST && p_149707_1_.isSideSolid(p_149707_2_ - 1, p_149707_3_, p_149707_4_, EAST ))) {
//currentSideOn = dir; //replaced with onBlockPlaced method
return true;
}
return false;*/
return true;
}
public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_)
{
//do nothing for now
}
}
Tile Entity Class
package tutorial.generic;
import net.minecraft.nbt.NBTTagCompound;
//import net.minecraft.network.INetworkManager;
import net.minecraft.network.INetHandler;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public class OmniTileEntity extends TileEntity{
//1=top, 2=bottom, 3=North, 4=South, 5=East, 6=West
public int face;
public void updateEntity() {
System.out.println("Hello");
}
public OmniTileEntity() {
}
@Override
public void writeToNBT(NBTTagCompound par1)
{
super.writeToNBT(par1);
par1.setInteger("face", face);
}
@Override
public void readFromNBT(NBTTagCompound par1)
{
super.readFromNBT(par1);
this.face = par1.getInteger("face");
}
}
Main Class
package tutorial.generic;
// This Import list will grow longer with each additional tutorial.
// It's not pruned between full class postings, unlike other tutorial code.
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.block.material.Material;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
//import cpw.mods.fml.common.Mod.Init; //Used in 1.5.2 and before
import cpw.mods.fml.common.Mod.Instance;
//import cpw.mods.fml.common.Mod.PostInit; //Used in 1.5.2 and before
//import cpw.mods.fml.common.Mod.PreInit; //Used in 1.5.2 and before
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
//import cpw.mods.fml.common.network.NetworkMod; //Used in 1.6.4 and before
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry; //Used in 1.6.4 and before
@Mod(modid="generic", name="Generic", version="0.0.0")
//@NetworkMod(clientSideRequired=true, serverSideRequired=false) //Used in 1.6.4 and before
public class Generic
{
public static Block genericDirt;
public static Block omniRail;
@Instance(value="generic")
public static Generic instance;
@SidedProxy(clientSide="tutorial.generic.client.ClientProxy",
serverSide="tutorial.generic.CommonProxy")
public static CommonProxy proxy;
@EventHandler
public void preInit(FMLPreInitializationEvent event)//loader method
{
genericDirt = new GenericBlock(Material.ground)
.setHardness(0.5F).setStepSound(Block.soundTypeGravel)
.setBlockName("genericDirt").setCreativeTab(CreativeTabs.tabBlock);
genericDirt.setHarvestLevel("shovel", 0);
genericDirt.setBlockTextureName("dirt");
GameRegistry.registerBlock(genericDirt, "genericDirt");
GameRegistry.registerTileEntity(tutorial.generic.OmniTileEntity.class, "OmniTileEntity");
omniRail = new OmniRailBlock()
.setHardness(0.7f).setStepSound(Block.soundTypeMetal)
.setBlockName("omniRail");
//omniRail.setBlockTextureName("Generic:OmniRail");//figure texture out later
GameRegistry.registerBlock(omniRail, "omniRail");
// End Basic Blocks
proxy.registerRenderers();
}
@EventHandler
public void init(FMLInitializationEvent event) {
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
// Stub Method
}
}
I've done some debug stuff but I cannot figure out why the tile entity is not be created. In other words, it never prints "Tile Entity Registered"
Please help me with this as this has been bugging me for a while now.
http://kck.st/PzXxKA 'Nuff Said
Edit: Oh yeah, forgot to say it works now
http://kck.st/PzXxKA 'Nuff Said