Posted October 6, 20159 yr I have this basic class with EnumRailDirection: package ultratechx.autotrains; import net.minecraft.block.Block; import net.minecraft.block.BlockRail; import net.minecraft.block.BlockRailBase; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.BlockPos; import net.minecraft.util.IStringSerializable; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class railControlBlock extends BlockRail implements ITileEntityProvider { public static final PropertyEnum PART = PropertyEnum.create("part", EnumPartType.class); public static final PropertyEnum SHAPE = PropertyEnum.create("shape", BlockRailBase.EnumRailDirection.class); private static String name = "railControlBlock"; private int part; public railControlBlock(int pnum) { super(); GameRegistry.registerTileEntity(railControl.class, name); if(pnum == 0) { setDefaultState(this.blockState.getBaseState().withProperty(PART, EnumPartType.MIDDLE).withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH)); this.part = 0; }else if(pnum == 1){ setDefaultState(this.blockState.getBaseState().withProperty(PART, EnumPartType.LEFT).withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH)); this.part = 1; }else if(pnum == 2){ setDefaultState(this.blockState.getBaseState().withProperty(PART, EnumPartType.RIGHT).withProperty(SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH)); this.part = 2; } GameRegistry.registerBlock(this, name); this.setCreativeTab(CreativeTabs.tabMisc); this.setUnlocalizedName(name); this.setHardness(2.0f); setBlockBounds(); this.setResistance(6.0f); this.setHarvestLevel("pickaxe", 2); this.isBlockContainer = true; } @Override public String toString() { return getName(); } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new railControl(); } public static String getName(){ return name; } @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos) { setBlockBoundsBasedOnState(worldIn, pos); return super.getSelectedBoundingBox(worldIn, pos); } public IProperty getShapeProperty() { return SHAPE; } public IProperty getPartProperty() { return PART; } public IBlockState getStateFromMeta(int meta) { return getDefaultState().withProperty(PART, EnumPartType.byMetadata(meta)).withProperty(SHAPE, BlockRailBase.EnumRailDirection.byMetadata(meta)); } @Override public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) { setBlockBounds(); } private void setBlockBounds() { setBlockBounds(0F, 0.0F, 0F, 1F, 0.125F, 1F); } public int getMetaFromState(IBlockState state) { return ((BlockRailBase.EnumRailDirection)state.getValue(SHAPE)).getMetadata(); } @Override public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos){ if(this.part == 2){ return state.withProperty(PART, EnumPartType.RIGHT); }else if(this.part == 1){ return state.withProperty(PART, EnumPartType.LEFT); }else{ return state.withProperty(PART, EnumPartType.MIDDLE); } } protected BlockState createBlockState() { return new BlockState(this, new IProperty[] { PART, SHAPE }); } public boolean isOpaqueCube() { return false; } /** * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) */ public boolean renderAsNormalBlock() { return false; } public int getRenderBlockPass() { return 1; } public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) { updateMultiBlockStructure(worldIn, pos.getX(), pos.getY(), pos.getZ()); } public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state){ updateMultiBlockStructure(worldIn, pos.getX(), pos.getY(), pos.getZ()); } public void updateMultiBlockStructure(World world, int x, int y, int z){ isMultiBlockStructure(world, x, y, z); } public boolean isMultiBlockStructure(World world, int x1, int y1, int z1){ boolean mStructure = false; boolean currentCheckStructure = true; for(int x3 = 0; x3 < 3; x3++){ for(int z3 = 0; z3 < 3; z3++){ BlockPos neighbourPos = new BlockPos(x1 - x3, y1, z1 - z3); IBlockState neighbourState = world.getBlockState(neighbourPos); Block neighbourBlock = neighbourState.getBlock(); if(currentCheckStructure && neighbourBlock != AutoTrains.railControl){ System.out.println("this is not a multi block structure"); currentCheckStructure = false; }else{ System.out.println("this is a multi block structure"); } } } return false; } protected void onNeighborChangedInternal(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) { //whenever the blocks around it change } public static enum EnumPartType implements IStringSerializable { MIDDLE(0, "middle"), LEFT(1, "left"), RIGHT(2, "right"); private static final EnumPartType[] META_LOOKUP = new EnumPartType[values().length]; private final int meta; private final String name; private EnumPartType(int meta, String name) { this.meta = meta; this.name = name; } public int getMetadata() { return this.meta; } public String toString() { return this.name; } public String getName() { return this.name; } public static EnumPartType byMetadata(int meta) { if (meta < 0 || meta >= META_LOOKUP.length) { meta = 0; } return META_LOOKUP[meta]; } static { EnumPartType[] var0 = values(); int var1 = var0.length; for (int var2 = 0; var2 < var1; ++var2) { EnumPartType var3 = var0[var2]; META_LOOKUP[var3.getMetadata()] = var3; } } } } but it wont turn when it should like a normal rail, any ideas? I'm working on something big! As long as there arent alot of big issues... [D
October 6, 20159 yr Author nevermind, i fixed it by adding this into my onBlockAdded method after taking a look at the BlockRailBase class: if (!worldIn.isRemote) { state = this.func_176564_a(worldIn, pos, state, true); } I'm working on something big! As long as there arent alot of big issues... [D
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.