Jump to content

TheRedDevil

Members
  • Posts

    9
  • Joined

  • Last visited

Posts posted by TheRedDevil

  1. If I did store the BlockType inside the tileEntity is it possible to create recipes that uses each blockType?

    Was main reason I stored the BlockType inside the metadata so I could create recipes for each metadata version.

     

    I've not looked into 1.8/1.9 recipes wasn't sure if it was possible.

     

    I have all code working now will keep it how it is :)

  2. Should I still use getStateFromMeta/getMetaFromState to store the "BLOCKTYPE"?

    @Override
        public IBlockState getStateFromMeta(int meta)
        {
            return this.getDefaultState().withProperty(BLOCKTYPE, EnumBlockType.byMetaData(meta));
        }
    
        @Override
        public int getMetaFromState(IBlockState state)
        {
            return ((EnumBlockType)state.getValue(BLOCKTYPE)).getMetadata();
        }
    
        @Override
        protected BlockState createBlockState()
        {
            return new BlockState(this, BLOCKTYPE, FACING);
        }
    
        @Override
        public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
        {
            return state.withProperty(FACING, getFacing(worldIn, pos));
        }
    

     

    When I place to block ingame it has the correct block type / facing n/e/s/w,

    but when I right click the block it's placing the block in the north face not west.

    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
        {
            Block testBlock = ModBlocks.testBlock;
            IBlockState testState = testBlock.getDefaultState();
    
            worldIn.setBlockState(new BlockPos(pos.getX() + 2, pos.getY(), pos.getZ()), testState.withProperty(FACING, EnumFacing.WEST));
    return true;
    }
    

     

     

     

     

  3. I've removed the tileEntity and managed to place blocks with the correct blockType property but having few problems merging the facing property together.

     

    Believe I need to combine these two lines together but having trouble merging both returns into one

     

    Method I'm having trouble getting both property to work together.

    @Override
        public int getMetaFromState(IBlockState state)
        {
            return  state.getValue(FACING).getIndex();
            //return state.getValue(BLOCKTYPE).getMetadata();
        }
    

  4. this is the block code, the facing property gets assigned when the block is placed.

    public class BlockTest extends Block
    {
        public static final IProperty<EnumFacing> FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
        public static final PropertyEnum BLOCKTYPE = PropertyEnum.create("block", EnumBlockType.class);
    
    
        public BlockTest(String unlocalizedName)
        {
            super(Material.stone);
        }
    
        @Override @SideOnly(Side.CLIENT)
        public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> list)
        {
            for(EnumBlockType EnumBlockType : EnumBlockType.values())
            {
                list.add(new ItemStack(item, 1, EnumBlockType.getMetadata()));
            }
        }
    
        @Override
        public IBlockState getStateFromMeta(int meta)
        {
            return this.getDefaultState().withProperty(BLOCKTYPE, EnumBlockType.byMetaData(meta));
        }
    
        @Override
        public int getMetaFromState(IBlockState state)
        {
            return ((EnumBlockType)state.getValue(BLOCKTYPE)).getMetadata();
        }
    
        @Override
        protected BlockState createBlockState()
        {
            return new BlockState(this, BLOCKTYPE, FACING);
        }
    
        @Override
        public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
        {
            return state.withProperty(FACING, getFacing(worldIn, pos));
        }
    
        @Override
        public boolean hasTileEntity(IBlockState state)
        {
            return true;
        }
    
        @Override
        public TileEntity createTileEntity(World world, IBlockState state)
        {
            return new TileEntityBlockTest();
        }
    
        public TileEntityBlockTest getTileEntity(IBlockAccess world, BlockPos pos)
        {
            return (TileEntityBlockTest) world.getTileEntity(pos);
        }
    
        public EnumFacing getFacing(IBlockAccess world, BlockPos pos)
        {
            return getTileEntity(world, pos).getFacing();
        }
    
        public void setFacing(IBlockAccess world, BlockPos pos, EnumFacing facing)
        {
            getTileEntity(world, pos).setFacing(facing);
        }
    
        @Override
        public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
        {
            setFacing(worldIn, pos, BlockPistonBase.getFacingFromEntity(worldIn, pos, placer));
        }
    
        public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
        {
            Block testBlock = ModBlocks.testBlock;
            IBlockState testState = testBlock.getDefaultState();
    
            //attempts to get the block placed with right property
            worldIn.setBlockState(new BlockPos(pos.getX() + 2, pos.getY(), pos.getZ()), testState.withProperty(FACING, EnumFacing.WEST));
    
            worldIn.setBlockState(new BlockPos(pos.getX() + 4, pos.getY(), pos.getZ()), ModBlocks.testBlock.getDefaultState().withProperty(FACING, EnumFacing.WEST));
    
    
            return true;
        }
    }
    

  5. I've created a block that stores the rotation data inside the tileentity.

     

    The problem I'm having is when I right click the custom block I want it to create the same block 4 blocks away.

    When I right click the block it places the block but facing North not any of the other directions.

     

    The code I've tried to use inside the block code:

    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) 
        {
            Block testBlock = ModBlocks.testBlock;
            IBlockState testState = testBlock.getStateFromMeta(getFabricType(state));
    
            //attempts to get the block placed with right property
            worldIn.setBlockState(new BlockPos(pos.getX() + 2, pos.getY(), pos.getZ()), testState.withProperty(FACING, EnumFacing.WEST));
    
            worldIn.setBlockState(new BlockPos(pos.getX() + 4, pos.getY(), pos.getZ()), ModBlocks.testBlock.getDefaultState().withProperty(FACING, EnumFacing.WEST));
    
    
            return true;
        }
    

     

    The tileEntity code: I think the problem is caused by this line "private EnumFacing facing = EnumFacing.NORTH" not sure how I could alter this code to not change a placed block to North rotation.

     

     

    public class TileEntityTest extends TileEntity
    {
        [color=red]private EnumFacing facing = EnumFacing.NORTH;[/color]
    
        public EnumFacing getFacing()
        {
            return facing;
        }
    
        public void setFacing(EnumFacing facing)
        {
            this.facing = facing;
            markDirty();
        }
    
        @Override
        public void readFromNBT(NBTTagCompound compound)
        {
            super.readFromNBT(compound);
            facing = EnumFacing.getFront(compound.getInteger("facing"));
        }
    
        @Override
        public void writeToNBT(NBTTagCompound compound)
        {
            super.writeToNBT(compound);
            compound.setInteger("facing", facing.getIndex());
        }
    
        @Override
        public Packet getDescriptionPacket()
        {
            NBTTagCompound nbttagcompound = new NBTTagCompound();
            this.writeToNBT(nbttagcompound);
            return new S35PacketUpdateTileEntity(this.getPos(), this.getBlockMetadata(), nbttagcompound);
        }
    
        @Override
        public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet)
        {
            readFromNBT(packet.getNbtCompound());
            getWorld().markBlockForUpdate(getPos());
        }
    
        @Override
        public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate)
        {
            return oldState.getBlock() != newSate.getBlock();
        }
    }
    

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.